import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
// https://vitejs.dev/config/
export default defineConfig(({mode})=>{
  const env = loadEnv(mode, process.cwd())
  console.log('当前运行环境：',mode)
  console.log('当前运行的环境变量',loadEnv(mode,__dirname))
  return  {
            plugins: [vue()],

            resolve:{
              alias:{
                "@":resolve(__dirname, './src')
              }
            },

            css:{
              preprocessorOptions:{
                less:{
                  javascriptEnabled:true
                }
              }
            },

            server:{
                port: 3001,
                host: '0.0.0.0',
                hmr: true,
                // 配置代理
                proxy: {
                    '/api': {
                        target: env.VITE_BASE_URL,
                        changeOrigin: true,
                        rewrite: (path) => path.replace(/^\/api/, '')
                    },
                }
            }
         }
})
